import BBRequest from "./request";
import { BASE_URL, TIME_OUT } from "./request/config";
import localCache from "../utils/cache";

const bbRequest = new BBRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      //携带token的拦截
      const token = localCache.getCache("token");
      if (token) {
        //先进行判断
        if(config && config.headers){
            config.headers.Authorization = `Bearer ${token}`;
        }
      }
      return config;
    },
    requestInterceptorCatch: (err) => {
      return err;
    },
    responseInterceptor: (res) => {
      return res;
    },
    responseInterceptorCatch: (err) => {
      return err;
    },
  },
});
export default bbRequest;
